import { reactive, ref } from "vue";

export default function InitHook() {
	// 日期选择器
	const frameworkOptions = ref<any[]>([]);
	const getterFrameworkOptions = () => {
		const now = new Date();
		const year = now.getFullYear(); // 年份（如 2024）
		const month = now.getMonth() + 1; // 月份（0-11，需+1 转为 1-12）
		const dayOfMonth = now.getDate(); // 当月第几天
		let day = now.getDay();
		let tip = "今天";
		for (let i = 0; i < 4; i++) {
			if (i === 0) tip = "今天";
			else {
				if (day === 6) {
					day = 0;
				} else {
					day++;
				}
				switch (day) {
					case 0:
						tip = "周日";
						break;
					case 1:
						tip = "周一";
						break;
					case 2:
						tip = "周二";
						break;
					case 3:
						tip = "周三";
						break;
					case 4:
						tip = "周四";
						break;
					case 5:
						tip = "周五";
						break;
					case 6:
						tip = "周六";
						break;
				}
			}
			frameworkOptions.value.push({
				label: `${month}-${dayOfMonth + i}`,
				value: `${year}-${month}-${dayOfMonth + i}`,
				tip: tip
			});
		}
		formState.day = `${year}-${month}-${dayOfMonth}`;
	};
	const formState = reactive<any>({
		day: "",
		price: 1,
		startTime: "10:00",
		endTime: ""
	});
	const priceList = ref<any>([
		{
			label: "4小时套餐",
			price: "118",
			value: 1,
			hour: 4
		},
		{
			label: "5小时套餐",
			price: "148",
			value: 2,
			hour: 5
		},
		{
			label: "8小时套餐",
			price: "200",
			value: 3,
			hour: 8
		},
		{
			label: "4小时套餐",
			price: "118",
			value: 4,
			hour: 4
		},
		{
			label: "4小时套餐",
			price: "118",
			value: 5,
			hour: 4
		},
		{
			label: "4小时套餐",
			price: "118",
			value: 6,
			hour: 4
		},
		{
			label: "4小时套餐",
			price: "118",
			value: 7,
			hour: 4
		},
		{
			label: "4小时套餐",
			price: "118",
			value: 8,
			hour: 4
		}
	]);
	let dateList = ref<Array<any>>([]);
	// 生成 时间点
	const generateTime = () => {
		let start = new Date().getHours();
		let result: Array<any> = [start];
		let target: any = start;
		for (let i = 0; i < 23; i++) {
			if (target === "次日") {
				target = 1;
			} else {
				if (target >= 23) {
					target = "次日";
				} else {
					target = target + 1;
				}
			}
			result.push(target);
		}
		console.log("result", result);
		dateList.value = result;
	};
	return {
		frameworkOptions,
		formState,
		getterFrameworkOptions,
		priceList,
		generateTime,
		dateList
	};
}
